package ac.svn.accesscontrol.ui.renderer;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;

import ac.framework.ui.shadowed.white.WhiteGradientLabel;
import ac.svn.accesscontrol.store.IResources;
import ac.svn.accesscontrol.store.ISVNItem;
import ac.svn.accesscontrol.ui.DropShadowBorder;
import ac.svn.accesscontrol.ui.IListItemTextFormatter;
import ac.svn.accesscontrol.ui.helper.formatter.LocationItemNameFormatter;
import ac.svn.accesscontrol.utils.UIUtility;
import ac.svn.accesscontrol.utils.Utility;

public class LocationListCellRenderer extends WhiteGradientLabel implements ListCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private IListItemTextFormatter textFormatter;
	private Border defBorder;    

	public LocationListCellRenderer()
	{
		super();
		//setOpaque(true);
		setBackground(Color.WHITE);
		setIcon(Utility.getImageIcon(IResources.LOC_ICN_URL));

		defBorder = new DropShadowBorder(Color.BLACK,3,0.5f,0,false,false,true,true); 
		setBorder(defBorder);

		textFormatter = new LocationItemNameFormatter();

		setPreferredSize(new Dimension(300,30));
	}

	@Override
	public Component getListCellRendererComponent(JList arg0, Object value,
			int arg2, boolean isSelected, boolean arg4) {
		ISVNItem item = (ISVNItem) value;
		if(null != value)
		{
			if(null != textFormatter)
			{
				setText(textFormatter.formatString(value));
				setToolTipText(textFormatter.formatToolTip(value));
			}
			else
			{
				setText(item.getName());
				setToolTipText(item.getTooltipText());
			}
		}
		else
		{
			setText("...");
		}
		if(isSelected)
		{
			setBorder(UIUtility.setAllShadowedBorder(null));
			setUpperColor(new Color(153,51,255));
			setLowerColor(Color.WHITE);
			
		}
		else
		{
			setBorder(defBorder);   
			setUpperColor(Color.LIGHT_GRAY);
			setLowerColor(Color.WHITE);
		}
//		/setReverseGradient(isSelected);
		setForeground(Color.BLACK);

		return this;
	}

}
